package dao;

import java.util.List;

import entity.Room;

public class RoomDao {

	public List<Room> select(String where) {
		return DbHepler.executeQuery("select Room.*,RoomType.name roomtype_name, RoomType.price roomtype_price"
				+ " from Room inner join RoomType on room.RoomType_id=RoomType.id "+where, Room.class);
	}
	
	public List<Room> login(String name,String pass) {
		return DbHepler.executeQuery("select * from room "
				+ " where name='"+name+"' and pass='"+pass+"'", Room.class);
	}
	
	public int insert(Room model) {
		return DbHepler.executeUpdate("insert into room (name,status,RoomType_id) values(?,?,?)", model.getName(),model.getStatus(),model.getRoomtype_id());
	}
	
	public int update(Room model) {
		return DbHepler.executeUpdate("update room set name=?,RoomType_id=? where id=?",model.getName(),model.getRoomtype_id(), model.getId());
	}
	
	public int updatestatus(int id, int status) {
		return DbHepler.executeUpdate("update room set status=? where id=?",status, id);
	}
	
	public int delete(int id) {
		return DbHepler.executeUpdate("delete from room where id=?", id);
	}
	
	public Room getbyid(int id) {
		List<Room> list=DbHepler.executeQuery("select * from room where id=?", Room.class,id);
		return list.get(0);
	}
	
}
